

import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.cloudgarden.resource.SWTResourceManager;
import java.awt.Frame;
import java.awt.Panel;
import net.miginfocom.swt.MigLayout;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class PrimalityTests extends org.eclipse.swt.widgets.Composite {

	private Menu menu1;
	private PrimalityCheckAlgorithmGroup compositeMillerRabinAlgorithm;
	private PrimalityCheckAlgorithmGroup compositeAgrawalKayalSaxenAlgorithm;
	private PrimalityCheckAlgorithmGroup compositeSolovayStrassenAlgorithm;
	private Composite compositePrimalityAlgorithms;
	private InputData compositeInputData;
	private PrimalityCheckAlgorithmGroup compositeFermatAlgorithm;
	private MenuItem aboutMenuItem;
	private MenuItem contentsMenuItem;
	private Menu helpMenu;
	private MenuItem helpMenuItem;
	private MenuItem exitMenuItem;
	private MenuItem closeFileMenuItem;
	private MenuItem saveFileMenuItem;
	private MenuItem newFileMenuItem;
	private MenuItem openFileMenuItem;
	private Menu fileMenu;
	private MenuItem fileMenuItem;
	
	private PrimalityCandidate primalityCandidate;
	private FermatPrimalityTest fermatPrimalityTest;
	private AgrawalKayalSaxenPrimalityTest agrawalKayalSaxenPrimalityTest;
	private MillerRabinPrimalityTest millerRabinPrimalityTest;
	private SolovayStrassenPrimalityTest solovayStrassenPrimalityTest;

	{
		//Register as a resource user - SWTResourceManager will
		//handle the obtaining and disposing of resources
		SWTResourceManager.registerResourceUser(this);
	}

	public PrimalityTests(Composite parent, int style) throws PrimalityCandidate.BadInputNumberException {
		super(parent, style);
		primalityCandidate = new PrimalityCandidate(100, 0.99d);
		fermatPrimalityTest = new FermatPrimalityTest(primalityCandidate);
		agrawalKayalSaxenPrimalityTest = new AgrawalKayalSaxenPrimalityTest(primalityCandidate);
		millerRabinPrimalityTest = new MillerRabinPrimalityTest(primalityCandidate);
		solovayStrassenPrimalityTest = new SolovayStrassenPrimalityTest(primalityCandidate);
		initGUI();
	}
	
	/**
	* Initializes the GUI.
	*/
	private void initGUI() {
		try {
			this.setBackground(SWTResourceManager.getColor(192, 192, 192));

			FormLayout thisLayout = new FormLayout();
			this.setLayout(thisLayout);
			{
				compositeInputData = new InputData(this, SWT.NONE);
				FillLayout compositeInputDataLayout1 = new FillLayout(org.eclipse.swt.SWT.HORIZONTAL);
				FormData compositeInputDataLData1 = new FormData();
				compositeInputDataLData1.width = 783;
				compositeInputDataLData1.height = 83;
				compositeInputDataLData1.left =  new FormAttachment(0, 1000, 0);
				compositeInputDataLData1.top =  new FormAttachment(0, 1000, 0);
				compositeInputDataLData1.right =  new FormAttachment(1000, 1000, 0);
				compositeInputData.setLayoutData(compositeInputDataLData1);
				compositeInputData.setLayout(compositeInputDataLayout1);
				GridLayout compositeInputDataLayout = new GridLayout();
				compositeInputDataLayout.makeColumnsEqualWidth = true;
				RowData compositeInputDataLData = new RowData();
			}
			{
				compositePrimalityAlgorithms = new Composite(this, SWT.NONE);
				FillLayout compositePrimalityAlgorithmsLayout = new FillLayout(org.eclipse.swt.SWT.HORIZONTAL);
				FormData compositePrimalityAlgorithmsLData = new FormData();
				compositePrimalityAlgorithmsLData.width = 783;
				compositePrimalityAlgorithmsLData.height = 162;
				compositePrimalityAlgorithmsLData.top =  new FormAttachment(0, 1000, 83);
				compositePrimalityAlgorithmsLData.left =  new FormAttachment(0, 1000, 0);
				compositePrimalityAlgorithmsLData.bottom =  new FormAttachment(1002, 1000, 0);
				compositePrimalityAlgorithmsLData.right =  new FormAttachment(1000, 1000, 0);
				compositePrimalityAlgorithms.setLayoutData(compositePrimalityAlgorithmsLData);
				compositePrimalityAlgorithms.setLayout(compositePrimalityAlgorithmsLayout);
				{
					PrimalityCheckAlghoritm alghoritm = fermatPrimalityTest;
					compositeFermatAlgorithm = new PrimalityCheckAlgorithmGroup(compositePrimalityAlgorithms, SWT.NONE, "Test Fermata", alghoritm);
					RowData compositeFermatAlgorithmLData = new RowData();
//					GridLayout composite1Layout = new GridLayout();
					compositeFermatAlgorithm.setLayoutData(compositeFermatAlgorithmLData);
//					composite1Layout.makeColumnsEqualWidth = true;
//					RowData composite1LData = new RowData();
				}
				{
					PrimalityCheckAlghoritm alghoritm = millerRabinPrimalityTest;
					compositeMillerRabinAlgorithm = new PrimalityCheckAlgorithmGroup(compositePrimalityAlgorithms, SWT.NONE, "Test Millera-Rabina", alghoritm);
					GridLayout compositeMillerRabinAlgorithmLayout = new GridLayout();
					compositeMillerRabinAlgorithmLayout.makeColumnsEqualWidth = true;
				}
				{
					PrimalityCheckAlghoritm alghoritm = solovayStrassenPrimalityTest;
					compositeSolovayStrassenAlgorithm = new PrimalityCheckAlgorithmGroup(compositePrimalityAlgorithms, SWT.NONE, "Test Solovaya-Strassena", alghoritm);
					GridLayout compositeSolovayStrassenAlgorithmLayout = new GridLayout();
					compositeSolovayStrassenAlgorithmLayout.makeColumnsEqualWidth = true;
				}
				{
					PrimalityCheckAlghoritm alghoritm = agrawalKayalSaxenPrimalityTest;
					compositeAgrawalKayalSaxenAlgorithm = new PrimalityCheckAlgorithmGroup(compositePrimalityAlgorithms, SWT.NONE, "Test Agrawala-Kayala-Saxena", alghoritm);
					GridLayout compositeAgrawalKayalSaxenAlgorithmLayout = new GridLayout();
					compositeAgrawalKayalSaxenAlgorithmLayout.makeColumnsEqualWidth = true;
				}
			}
			{
				menu1 = new Menu(getShell(), SWT.BAR);
				getShell().setMenuBar(menu1);
				{
					fileMenuItem = new MenuItem(menu1, SWT.CASCADE);
					fileMenuItem.setText("File");
					{
						fileMenu = new Menu(fileMenuItem);
						{
							openFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
							openFileMenuItem.setText("Open");
						}
						{
							newFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
							newFileMenuItem.setText("New");
						}
						{
							saveFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
							saveFileMenuItem.setText("Save");
						}
						{
							closeFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
							closeFileMenuItem.setText("Close");
						}
						{
							exitMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
							exitMenuItem.setText("Exit");
						}
						fileMenuItem.setMenu(fileMenu);
					}
				}
				{
					helpMenuItem = new MenuItem(menu1, SWT.CASCADE);
					helpMenuItem.setText("Help");
					{
						helpMenu = new Menu(helpMenuItem);
						{
							contentsMenuItem = new MenuItem(helpMenu, SWT.CASCADE);
							contentsMenuItem.setText("Contents");
						}
						{
							aboutMenuItem = new MenuItem(helpMenu, SWT.CASCADE);
							aboutMenuItem.setText("About");
						}
						helpMenuItem.setMenu(helpMenu);
					}
				}
			}
			this.layout();
			pack();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	* Auto-generated main method to display this 
	* org.eclipse.swt.widgets.Composite inside a new Shell.
	 * @throws PrimalityTests.BadInputNumberException 
	*/
	public static void main(String[] args) throws PrimalityCandidate.BadInputNumberException {
		Display display = Display.getDefault();
		Shell shell = new Shell(display);
		PrimalityTests inst = new PrimalityTests(shell, SWT.NULL);
		Point size = inst.getSize();
		shell.setLayout(new FillLayout());
		shell.layout();
		if(size.x == 0 && size.y == 0) {
			inst.pack();
			shell.pack();
		} else {
			Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
			shell.setSize(shellBounds.width, shellBounds.height);
		}
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}
	
	public String getTextCandidate() {
		return compositeInputData.getTextCandidate();
	}
	
	public String getTextAccuracy() {
		return compositeInputData.getTextAccuracy();
	}

}
